#pragma once

#include "CFWrapper.h"

class CDirVisitor : public IDirVisitor, public std::enable_shared_from_this<CDirVisitor>
{
public:
	CDirVisitor(const CF_CALLBACK_INFO *pCallbackInfo, LockExit lockExit, std::wstring strPathName);
	~CDirVisitor();

	INT64 GetKey() const override;
	void Cancel() override;
	bool IsCanceled() const override { return m_bCanceled; }
	void OnVisit(FileInfo fileInfo) override;
	void OnError() override;
	void Init();

private:
	void EnumLocalFiles();
	bool CanUpdate(const FIND_DATA& localInfo, const FileInfo& remoteInfo) const;
	void UpdatePlaceholder(FIND_DATA&& localInfo, FileInfo&& remoteInfo) const;
	void TransferPlaceholders();
	void DeleteExtraFiles() const;

	std::atomic_bool m_bCanceled;
	bool             m_bError;
	CF::CCbWrapper   m_cfCbWrapper;
	LockExit         m_lockExit;	// Prevent CloudManager from exiting
	std::wstring     m_strPathName;
	SRWLOCK          m_SRWLock = SRWLOCK_INIT;
	std::unordered_map<std::wstring, FIND_DATA> m_mapLocalInfos;
	std::unordered_map<std::wstring, FileInfo> m_mapRemoteInfos;
};
